<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<html>

<head>
    <meta charset="UTF-8">
    <title>未来小说网--搜索排行</title>
    <link rel="stylesheet" href="../../resources/font/iconfont.css" th:href="@{/resources/font/iconfont.css}">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="stylesheet" href="../../resources/css/all.css" th:href="@{/resources/css/all.css}">
    <script src="../../resources/js/jquery-3.4.1.min.js" th:src="@{/resources/js/jquery-3.4.1.min.js}"></script>
    <link rel="stylesheet" href="../../resources/css/search.css" th:href="@{/resources/css/search.css}">
</head>

<body>
    <div class="fixed-nav">
        <div class="cf" style="width: 1200px;margin: 0 auto;">
            <h1 class="top-logo">未来小说网</h1>
            <div class="nav-list site-nav fl">
                <ul>
                    <li th:each="tagTwo:${tags}" th:if="${tagTwoStat.index} lt 6">
                        <a class="search-info" th:text="${tagTwo}"></a>
                    </li>
                    <li class="more">
                        <a>更多<span></span></a>
                        <div class="dropdown">
                            <a>全部作品</a>
                            <a class="search-info" th:each=" tagTwo: ${tags}" th:if="${tagTwoStat.index} gt 5" th:text="${tagTwo}"></a>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="nav-list min-user fr">
                <ul>
                    <p id="pd" style="display: none" th:text="${session.currentAccount} eq null"></p>
                    <li id="min-search">
                        <form id="form" method="POST" th:action="@{/search(page=1,per_page=5)}">
                            <input class="search-box" id="goSearch" name="keywords" type="text" placeholder="请输入..." value="" style="padding: 5px;">
                            <input id="keyword" class="fixed-input hide" style="margin-left: 10px;margin-right: 4px;" type="hidden" name="searchBy" value="KEYWORDS">
                            <input class="submit-input" type="hidden" id="searchSubmitType" name="sortBy" value="BEST_MATCH">
                            <button id="search-btn" for="searchSubmit" type="submit" style="background-color: #2470bf;">
								<a style="padding-left: 5px;">
									<i class="fa fa-search" style="font-size:16px;color: #ffffff;margin: 16px 20px 0 0;"></i>
								 </a>
							</button>
                        </form>
                        <form id="form2" style="" th:action="@{/search(page=1,per_page=5)}" method="POST">
                            <input type="hidden" name="searchBy" th:value="${searchBy}">
                            <input type="hidden" id="sortBy" name="sortBy" th:value="${sortBy}">
                            <input type="hidden" name="keywords" th:value="${keywords}">
                        </form>
                        <li class="line"></li>
                    </li>
                    <li class="sign-out" th:if="${session.currentAccount} eq null">
                        <a id="fixed-login" th:href="@{/login(redirectTo=${@templateController.getRequestUri()}, errorMessage='请先登录')}">登录</a>
                        <a class="reg" th:href="@{/register}" target="_blank">注册</a>
                    </li>
                    <li class="sign-out" th:if="${session.currentAccount} ne null" th:each="user:${session.currentAccount}">
                        <p style="display: none" th:text="${session.currentAccount.uid.toString()}" id="AccoundId"></p>
                        <a th:text="${user.userName}"></a>
                        <a th:text="${'LV'+user.level}"></a>
                    </li>
                    <li class="line"></li>
                    <li class="book-shelf" id="top-book-shelf">
                        <a th:if="${session.currentAccount} ne null" th:href="${#request.contextPath}+'/user/'+${session.currentAccount.uid.toString()}" target="_blank">
                            <i class="fa fa-book" style="font-size:16px">我的书架</i>
                        </a>
                    </li>
                    <li class="avatar" th:each="user:${session.currentAccount}">
                        <a th:href="${#request.contextPath}+'/user/'+${session.currentAccount.uid.toString()}" target="_blank">
                            <img th:if="${session.currentAccount} eq null" src="../../resources/img/avatar.png" th:src="@{/resources/img/avatar.png}" style="border-radius: 50%;position: relative;top: 3px">
                            <img th:if="${session.currentAccount} ne null" th:src="${user.profileImgUrl}" style="border-radius: 50%;width: 40px;height: 40px;position: relative;top: 3px">
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div id="box">
        <div></div>
        <select id="Shelf" style="width:110px;margin-top:3px;float:left" class="blue-btn">
            <option selected>请选择收藏夹</option>
        </select>
        <button style="margin-top:3px;float: left" id="sureAdd" class="blue-btn" type="button">确定</button>
    </div>
    <div id="ShelfBox">
        <input type="text" class="input" id="addShelfInput"><button type="button" class="blue-btn" id="SureToAddShelf">确定</button>
    </div>
    <div class="main-content-wrap" id="main-content-wrap" style="background-color: #f5f5f5;">
        <div class="rank-header">
            <h3 style="font-size: 26px;line-height: 26px;margin-bottom: 15px;font-family:宋体;font-weight: 600;">
                搜索结果
            </h3>
            <div class="rank-toolbar-wrap" style="margin-bottom:20px;line-height: 50px;background-color: #fff;padding: 10px;">
                <div class="tool-box">
                    <div class="type-list cf">
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','RANDOM');$('#form2').submit();" sortBy="RANDOM">随机排序</a>
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','COPYRIGHT');$('#form2').submit();" sortBy="COPYRIGHT">版权排序</a>
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','PUBDATE');$('#form2').submit();" sortBy="PUBDATE">发布日期排序</a>
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','PUBLISHER');$('#form2').submit();" sortBy="PUBLISHER">出版社排序</a>
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','RATING_DESC');$('#form2').submit();" sortBy="RATING_DESC">评分排序</a>
                        <a href="javascript:;" class="SortBy" onclick="$('#sortBy').attr('value','SERIES');$('#form2').submit();" sortBy="SERIES">系列排序</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="rank-body" style="margin:10px 0;">
            <ul style="overflow: hidden;">
                <li th:each="novel:${novelIndexList}" th:if="${searchBy.name()} eq 'KEYWORDS'">
                    <span th:if="${#lists.isEmpty(novelIndexList)}" th:text="无搜索结果"></span>
                    <div class="book-rank-list" style="overflow: hidden;">
                        <div class="book-rank-img">
<!--                            <img th:src="${novel.coverImgUrl}" style="width: 100px;float: left;" />-->
                            <img th:if="${novel.coverImgUrl}" th:src="${novel.coverImgUrl}" style="width: 100px;float: left;" />
                            <img th:unless="${novel.coverImgUrl}" th:src="@{/resources/img/loading.jpg}" style="width: 100px;float: left;" />
                        </div>
                        <div class="book-rank-list-text">
                            <h4 style="font-size: 15px;font-weight: 400;" th:text="${novel.title}"></h4>
                            <p style="font-size: 10px;color: gray;margin-top: 10px;">
                                <span class="book-rank-writer" th:text="${novel.authors}"></span>
                                <city>|</city>
                                <span class="book-rank-type" th:text="${novel.tags}"></span>
                                <city>|</city>
                                <span class="book-rank-type" th:text="${'评分：'+novel.rating}"></span>
                            </p>
                            <span class="book-rank-synopsis" th:text="${novel.description}"></span>
                        </div>
                        <div class="rank-book-buttons">
                            <span class="rank-book-details" th:attr="novelId=${novel.uniqueId}">书籍详情</span>
                            <span class="rank-book-add" th:if="${session.currentAccount} ne null" th:attr="novelId=${novel.uniqueId}">加入书单</span>
                            <a class="rank-book-add" th:if="${session.currentAccount} eq null" th:href="@{/login(redirectTo=${@templateController.getRequestUri()})}" th:attr="novelId=${novel.uniqueId}">加入书单</a>
                        </div>
                    </div>
                </li>
            </ul>
            <ul style="overflow: hidden;">
                <div th:if="${searchBy.name()} eq 'CONTENT'">
                    <span th:if="${#lists.isEmpty(sectionList)}">无搜索结果</span>
                    <li th:each="section:${sectionList}" >
                        <div class="book-rank-list" style="overflow: hidden;">
                            <div class="book-rank-img">
                                <img th:src="${chapterIdToNovelIndexMap.get(section.fromChapter).coverImgUrl}" style="width: 100px;float: left;" />
                            </div>
                            <div class="book-rank-list-text">
                                <h4 style="font-size: 15px;font-weight: 400;" th:text="${chapterIdToNovelIndexMap.get(section.fromChapter).title}"></h4>
                                <p style="font-size: 10px;color: gray;margin-top: 10px;">
                                    <span class="book-rank-writer" th:text="${chapterIdToNovelIndexMap.get(section.fromChapter).authors}"></span>
                                    <city>|</city>
                                    <span class="book-rank-type" th:text="${chapterIdToNovelIndexMap.get(section.fromChapter).tags}"></span>
                                    <city>|</city>
                                    <span class="book-rank-mode" th:text="'评分：'+${chapterIdToNovelIndexMap.get(section.fromChapter).rating}"></span>
                                </p>
                                <span class="book-rank-synopsis" th:text="${chapterIdToNovelIndexMap.get(section.fromChapter).description}"></span>
                            </div>
                            <div class="rank-book-buttons">
                                <span class="rank-book-details" th:attr="novelId=${chapterIdToNovelIndexMap.get(section.fromChapter).uniqueId}">书籍详情</span>
                                <span class="rank-book-add" th:if="${session.currentAccount} ne null" th:attr="novelId=${chapterIdToNovelIndexMap.get(section.fromChapter).uniqueId}">加入书单</span>
                                <a class="rank-book-add" th:if="${session.currentAccount} eq null" th:href="@{/login(redirectTo=${@templateController.getRequestUri()})}" th:attr="novelId=${chapterIdToNovelIndexMap.get(section.fromChapter).uniqueId}">加入书单</a>
                            </div>
                        </div>
                        <span th:utext="${section.text}" style="color: black" class="content"></span>
                    </li>
                </div>
            </ul>
            <ul style="overflow: hidden;">
                    <li th:each="novel:${novelIndexList}" th:if="${searchBy.name()} eq 'HOT'">
                        <span th:if="${#lists.isEmpty(novelIndexList)}" th:text="无搜索结果"></span>
                        <div class="book-rank-list" style="overflow: hidden;">
                            <div class="book-rank-img">
                                <img th:src="${novel.coverImgUrl}" style="width: 100px;float: left;" />
                            </div>
                            <div class="book-rank-list-text">
                                <h4 style="font-size: 15px;font-weight: 400;" th:text="${novel.title}"></h4>
                                <p style="font-size: 10px;color: gray;margin-top: 10px;">
                                    <span class="book-rank-writer" th:text="${novel.authors}"></span>
                                    <city>|</city>
                                    <span class="book-rank-type" th:text="${novel.tags}"></span>
                                    <city>|</city>
                                    <span class="book-rank-type" th:text="${'评分：'+novel.rating}"></span>
                                </p>
                                <span class="book-rank-synopsis" th:text="${novel.description}"></span>
                            </div>
                            <div class="rank-book-buttons">
                                <span class="rank-book-details" th:attr="novelId=${novel.uniqueId}">书籍详情</span>
                                <span class="rank-book-add" th:if="${session.currentAccount} ne null" th:attr="novelId=${novel.uniqueId}">加入书单</span>
                                <a class="rank-book-add" th:if="${session.currentAccount} eq null" th:href="@{/login(redirectTo=${@templateController.getRequestUri()})}" th:attr="novelId=${novel.uniqueId}">加入书单</a>
                            </div>
                        </div>
                    </li>
            </ul>
            <ul style="overflow: hidden;">
                <li th:each="novel:${novelIndexList}" th:if="${searchBy.name()} eq 'PUBDATE'">
                    <span th:if="${#lists.isEmpty(novelIndexList)}" th:text="无搜索结果"></span>
                    <div class="book-rank-list" style="overflow: hidden;">
                        <div class="book-rank-img">
                            <img th:src="${novel.coverImgUrl}" style="width: 100px;float: left;" />
                        </div>
                        <div class="book-rank-list-text">
                            <h4 style="font-size: 15px;font-weight: 400;" th:text="${novel.title}"></h4>
                            <p style="font-size: 10px;color: gray;margin-top: 10px;">
                                <span class="book-rank-writer" th:text="${novel.authors}"></span>
                                <city>|</city>
                                <span class="book-rank-type" th:text="${novel.tags}"></span>
                                <city>|</city>
                                <span class="book-rank-type" th:text="${'评分：'+novel.rating}"></span>
                            </p>
                            <span class="book-rank-synopsis" th:text="${novel.description}"></span>
                        </div>
                        <div class="rank-book-buttons">
                            <span class="rank-book-details" th:attr="novelId=${novel.uniqueId}">书籍详情</span>
                            <span class="rank-book-add" th:if="${session.currentAccount} ne null" th:attr="novelId=${novel.uniqueId}">加入书单</span>
                            <a class="rank-book-add" th:if="${session.currentAccount} eq null" th:href="@{/login(redirectTo=${@templateController.getRequestUri()})}" th:attr="novelId=${novel.uniqueId}">加入书单</a>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="page-box" style="padding: 40px 0;position: relative;">
            <div class="pagination" style="position: absolute;right: 0;">
                <div class="box-page">

                </div>
            </div>
        </div>
    </div>


</body>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script th:inline="javascript" async>
    function popup_over(icon,color,contant){
        $('body').append('<div class="popup_over" style="text-align: center; line-height: 80px; left: 50%; top: 50%; transform: translate(-50%,-50%); background-color: white; position: fixed; width: 180px; height: 80px; border: 1px solid #D5D6D5; z-index: 1000;"><i class="iconfont '+icon+'" style="font-size: 30px;color: '+color+';"></i><span style="font-size: 16px; position: relative; bottom: 5px;"> '+contant+'</span></div>');
        setTimeout(function(){
            $('.popup_over').remove();
            // clear('.popup_over');
        },1500)
    };
    //添加收藏夹
    function addShelf() {
        const contextPath=/*[[${#request.getContextPath()}]]*/'http://localhost:8080/future-novel';
        $.ajax({
            url: contextPath+"/api/bookSelf/create",
            type: "POST",
            datatype: "JSON",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify({
                title:  $("#addShelfInput").val().length==0?null:$("#addShelfInput").val(),
            }),
            success: function(data) {
                console.log(data);
                $("#ShelfBox").css("display", "none");
                popup_over('icon-happy-l','#00ff0f',"添加成功");
            },
            error: function(data) {
                console.log(data);
            }
        })
    }
    console.log($("#ShelfLength").text());
    $(".rank-book-buttons").on("click", ".rank-book-add", function() {
        if($("#ShelfLength").text()==1){
            $("#ShelfBox").css("marginTop",-30+"px");
            popup_over('icon-happy-l', '#00ff0f', "请先创建收藏夹");
            $("#SureToAddShelf").click(function () {
                addShelf();
                popup_over('icon-happy-l', '#00ff0f', "创建成功");
                setTimeout(function () {
                    window.location.reload();
                },1500)
            })
        }else{
            $("#box").css("marginTop",-30+"px");
            const str=$(this).attr("novelId");
            $("#sureAdd").click(function() {
                console.log($(this).attr("novelId"));
                $("#box").css("marginTop",-90+"px");
                AddBookSelf($("#Shelf option:selected").attr("Shelfid"),str)
            })
        }

    })
    function getAllAcconutShelf() {
            const contextPath=/*[[${#request.getContextPath()}]]*/'http://localhost:8080/future-novel';
            $.ajax({
            url:contextPath + '/api/account/'+$("#AccoundId").text()+'/bookSelves',
            type: "GET",
            datatype: "json",
            contentType: "application/json;charset=UTF-8",
            data: {},
            success: function(data) {
                if(data!=undefined){
                    for (var i = 0; i < data.length; i++) {
                        $("#Shelf").append("<option ShelfId='" + "" + data[i].uniqueId + "" + "'>" + "" + data[i].title + "" + "</option>")
                    }
            }
               else{
                   $("#box").append("<p style='display: none;' id='ShelfLength'>1</p>");
                }
            },
            error: function(data) {
                console.log(data);
            }
        })
    }
    if($("#pd").text()=="false") {
        getAllAcconutShelf();
    }
    function AddBookSelf(Id,novelId) {
        const contextPath=/*[[${#request.getContextPath()}]]*/'http://localhost:8080/future-novel';
        $.ajax({
            url: contextPath+"/api/bookSelf/" + Id + "/add",
            type: "POST",
            datatype: "json",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify({
                novelIndexId: novelId
            }),
            success: function(data) {
                console.log(data);
                popup_over('icon-happy-l','#00ff0f',"添加成功");
            },
            error: function(data) {
                console.log(data);
            }
        })
    }
    function submitForm(index) {
        const contextPath=/*[[${#request.getContextPath()}]]*/'http://localhost:8080/future-novel';
        var str = contextPath+"/search?page=" + index+"&per_page=5";
        $("#form").attr("action", str);
        $("#form2").attr("action", str);
    }
    if ([[${totalPage}]] != 1) {
        for (var i = 1; i <= [[${totalPage}]]; i++) {
            $(".box-page").append("<span class=\"rank-page\">" + "" + i + "" + "</span>")
        }
    }
    $(".box-page").on("click", ".rank-page", function() {
        $(this).toggleClass("tab");
        $(this).siblings().removeClass("tab");
        submitForm($(this).text());
        $("#form2").submit();
    })
    $(".rank-book-buttons").on("click", ".rank-book-details", function() {
        const contextPath=/*[[${#request.getContextPath()}]]*/'http://localhost:8080/future-novel';
        window.location.href = contextPath +"/novel/"+ $(this).attr("novelId") + "/view";
    })
    $(".SortBy").click(function () {
        $("#searchSubmitType").attr("value",$(this).attr("SortBy"));
    })
    // 按照标签搜索
    $(".search-info").click(function () {
        console.log($(this).text());
        $("#goSearch").attr("value", $(this).text());
        $("#form").submit();
    });
</script>

</html>